<?php
namespace jy_weishop_en;
defined('BY_JYA') or exit('error');
/*
	编辑商品
*/
class setgoods extends \plugin{
	public function edit($id=0,$onepluginname=''){
		if($id){
			$isread=pdo_count('jy_weishop_order_goods',array('goodsid'=>$id),'id');
			$item=pdo_get('jy_weishop_goods',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			if($item['pluginname']=='jy_taobaoke' && $item['pluginname']=='jy_jdk' && $item['pluginname']=='jy_pdd'){
				exi('淘宝客，京东客，拼多多客等商品不允许编辑','error','list');
			}
			$item['dispatch']=pdo_get('jy_weishop_goods_dispatch',array('goodsid'=>$id));
			if($item['istime']==1){
				$item['cuxiao']=2;
			}elseif($item['isdiscount']==1){
				$item['cuxiao']=1;
			}
			$item['api_data']=json_decode($item['api_data'],true);
			$specs_list=pdo_getall('jy_weishop_goods_spec',array('goodsid'=>$id,'uniacid'=>$_SESSION['uniacid']),array('id','title'),'','paixu asc');
			if($specs_list){
					foreach($specs_list as &$row){
						$row['options']=pdo_getall('jy_weishop_goods_spec_item',array('specid'=>$row['id'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'','paixu asc');
					}
					$item['specs']['specs']=$specs_list;
			}
			$item['oldspecs']=$item['specs'];
			$option_list=pdo_getall('jy_weishop_goods_option',array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$id),array('id','specs','thumb','stock','price','productprice','costprice','goodssn','productsn','weight'),'','paixu asc');
			if($option_list){
					foreach($option_list as &$i){
						$i['specs']=explode('_',$i['specs']);
						foreach($i['specs'] as $j){
							$op=pdo_get('jy_weishop_goods_spec_item',array('id'=>intval($j)),array('id','specid','title'));
							if($op['specid']){
								$i[$op['specid']]=$op;
							}
						}
						$i['num']=$i['stock'];
						$i['old_price']=$i['productprice'];
						$i['cost_price']=$i['costprice'];
						$i['bm']=$i['goodssn'];
						$i['tm']=$i['productsn'];
						$i['image']=$i['thumb'];
					}
					$item['specs']['tds']=$option_list;
			}
			$item['api_taocans']=pdo_getall('jy_weishop_goods_option',array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$id,'specs'=>''),array('id','thumb','title','unit','stock','price','productprice','costprice','goodsnum'),'','paixu asc');
		}else{
			$item=array('status'=>1,'total'=>188,'totalcnf'=>2);
		}
		$item['verifygoodslimitdate']=$item['verifygoodslimitdate']?date('Y-m-d H:i',$item['verifygoodslimitdate']):date('Y-m-d H:i',time());
		if(!$item['dispatch']){
			$item['dispatch']=array('fullmoney'=>'');
		}
		$shopset=$this->plugin_setting('shopset');
		$return['offcodeunit']=$shopset['offcodeunit'];
		foreach($return['offcodeunit'] as $k=>&$offv){
			$offv['id']=$k;
		}
		if(intval($shopset['goodscodenum'])>0){
			$goodsnum=pdo_count('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid']),'id');
			$shopset['goodscodenum']=intval($shopset['goodscodenum']);
			$item['offcode']=$selfnumber=sprintf("%0".$shopset['goodscodenum']."d", $goodsnum);
		}
		if($item['showlevels']){
			$fastvalue=substr($item['showlevels'],0,1);
			if($fastvalue!=';'){
				$item['showlevels']=';'.$item['showlevels'];
			}
			$lastvalue=substr($item['showlevels'],-1,1);
			if($lastvalue!=';'){
				$item['showlevels']=$item['showlevels'].';';
			}
		}else{
			$item['showlevels']='';
		}
		if($item['buylevels']){
			$fastvalue=substr($item['buylevels'],0,1);
			if($fastvalue!=';'){
				$item['buylevels']=';'.$item['buylevels'];
			}
			$lastvalue=substr($item['buylevels'],-1,1);
			if($lastvalue!=';'){
				$item['buylevels']=$item['buylevels'].';';
			}
		}else{
			$item['buylevels']='';
		}
		if($item['showgroups']){
			$fastvalue=substr($item['showgroups'],0,1);
			if($fastvalue!=';'){
				$item['showgroups']=';'.$item['showgroups'];
			}
			$lastvalue=substr($item['showgroups'],-1,1);
			if($lastvalue!=';'){
				$item['showgroups']=$item['showgroups'].';';
			}
		}else{
			$item['showgroups']='';
		}
		if($item['buygroups']){
			$fastvalue=substr($item['buygroups'],0,1);
			if($fastvalue!=';'){
				$item['buygroups']=';'.$item['buygroups'];
			}
			$lastvalue=substr($item['buygroups'],-1,1);
			if($lastvalue!=';'){
				$item['buygroups']=$item['buygroups'].';';
			}
		}else{
			$item['buygroups']='';
		}
		if($_SESSION['current_plugin']=='jy_pingdd'){
			$item['is_group']=1;
		}
		if($item['api_pluginname']=='jy_supplier'){
			$item['supplier_id']=$item['api_id'];
		}
		$item['supplier_id']=$item['supplier_id']?:0;
		//赠送虚拟币
		$gcredit=pdo_get('jy_weishop_goods_credit',array('goods_id'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
		$gcredit['credit_set']=json_decode($gcredit['credit_set'],true);
		$item['gcredit_id']=$gcredit['id'];
		$item['gcredit_sendtype']=$gcredit['sendtype']?:0;
		$item['gcredit_type']=$gcredit['type'];
		$item['gcredit_credit']=$gcredit['credit'];
		$item['gcredit_credit_set']=$gcredit['credit_set'];
		$return['item']=$item;
		$return['item']['storeids']=json_decode($return['item']['storeids'],true);
		$return['item']['param']=json_decode($return['item']['param'],true);
		$return['item']['images']=json_decode($return['item']['images'],true);
		$return['item']['diyfields']=$return['item']['diyfields']?json_decode($return['item']['diyfields'],true):array();
		$return['item']['pcd']=json_decode($return['item']['pcd'],true);
		$return['item']['diyprice']=json_decode($return['item']['diyprice'],true);
		$return['item']['deductset']=json_decode($return['item']['deductset'],true);
		$return['item']['commissions']=json_decode($return['item']['commissions'],true);
		$return['item']['no_oldprice']=intval($return['item']['api_data']['no_oldprice']);
		$return['item']['no_oldpriceline']=intval($return['item']['api_data']['no_oldpriceline']);
		$return['item']['oldpricetitle']=$return['item']['api_data']['oldpricetitle'];
		$return['item']['api_istaocan']=$return['item']['api_data']['istaocan']?:0;
		$catelevel=$shopset['level']?3:2;
		$setting=$this->plugin_setting('setting');
		$price_title=$setting['price_title']?:'商品';
		$htmls=array(
			'type'=>'edit',
			'post'=>'post',
			'tabs'=>array(
				array('op'=>'list','title'=>'返回商品列表'),
			),
			'edit_tab'=>true,
			'edits'=>array(
				array(
					'title'=>'基本信息',
					'list'=>array(
						array('name'=>'paixu','title'=>'排序','type'=>'string','help'=>'数字越大，排名越靠前'),
						array('name'=>'title','title'=>'商品名称','type'=>'string'),
						array('name'=>'image','title'=>'商品主图','type'=>'image','help'=>'建议尺寸：宽580px*高580rpx'),
						array('name'=>'video','title'=>'商品视频','type'=>'video','help'=>'默认优选显示视频，如果想关闭，请移步基础设置-其他设置'),
						array('name'=>'images','title'=>'商品展示图','type'=>'images','help'=>'<red>前端展示会追加首图，请勿重复添加</red>，建议尺寸：宽580px*高580rpx'),
						array('name'=>'subtitle','title'=>'副标题','type'=>'text','help'=>'副标题的长度请控制在100字以内'),
						array('name'=>'shorttitle','title'=>'短标题','type'=>'string','help'=>'商品短标题 用于快递打印,以及小型热敏打印机打印'),
						//array('name'=>'keywords','title'=>'关键字','type'=>'string','help'=>'商品关键字,能准确搜到商品的,比如 : 海尔电视|电视 之类的'),
						array('name'=>'type','title'=>'商品类型','type'=>'radio','options'=>'type','read'=>$isread,'help'=>'如果已产生订单的商品，不支持修改商品类型！（日常使用中：只有实体物品+记时/记次商品才需要核销）'),
						array('name'=>'virtualsend','title'=>'是否自动发货','type'=>'switch','show'=>array('type'=>1)),
						array('name'=>'virtualsendcont','title'=>'自动发货内容','type'=>'text','show'=>array('type'=>1,'virtualsend'=>1)),
						array('name'=>'virtual_template_id','title'=>'选择卡密模版','type'=>'select','show'=>array('type'=>2),'options'=>'virtual_templates','help'=>''),
						array('type'=>'select'.$catelevel.'_line','name'=>'pcate','options'=>'pcates','title'=>'选择分类','help'=>'[温馨提示]：如果场景下，开启了独立商品，此处只显示本场景下的分类',
							'name2'=>'ccate','options2'=>'ccates','title2'=>'请选择二级分类',
							'name3'=>'scate','options3'=>'scates','title3'=>'请选择三级分类',
						),
						array('name'=>'saletype','title'=>'商品属性','type'=>'checkbox','options'=>'saletype'),
						array('name'=>'price','title'=>$price_title.'价格','type'=>'string','help'=>'<red>商品价格</red>解释：如果门店设置了商品价格，将以门店价格为准！'),
						array('name'=>'costprice','title'=>'成本价','type'=>'string','show'=>array('supplier_id'=>0)),
						array('name'=>'costprice','title'=>'供应价','type'=>'copy','show'=>array('supplier_id >'=>0),'help'=>'由供货商发布商品，设置供应价格'),
						array('name'=>'no_oldprice','title'=>'不显示原价？','type'=>'switch'),
						array('name'=>'originalprice','title'=>'原价','type'=>'string','show'=>array('no_oldprice'=>0)),
						array('name'=>'oldpricetitle','title'=>'原价自定义','type'=>'string','show'=>array('no_oldprice'=>0),'help'=>'例如:市场价、京东价、天猫价、苏宁价、淘宝价'),
						array('name'=>'no_oldpriceline','title'=>'不显示原价删除线？','type'=>'switch','show'=>array('no_oldprice'=>0),'help'=>'请填写真实市场价/同行价，方便后台统计节省数据'),
						array('name'=>'marketprice','title'=>'市场价','type'=>'string','help'=>'请填写真实市场价/同行价，方便后台统计节省数据'),
						array('name'=>'groupprice','title'=>'拼单价','type'=>'string','show'=>array('is_group'=>1),'help'=>'这里要填具体价格'),
						array('name'=>'groupnum','title'=>'拼单数','type'=>'string','show'=>array('is_group'=>1),'help'=>'这里要填拼单的，成单人数(成团人数)！比如2人'),
						array('name'=>'grouptime','title'=>'拼单时间','type'=>'unitstring','unit'=>'小时','show'=>array('is_group'=>1),'help'=>'这里要填每个拼单有效时间，默认48小时'),
						array('name'=>'unit','title'=>'商品单位','type'=>'string'),
						array('name'=>'seven','title'=>'退换货','type'=>'switch','help'=>'支持单商品退换货后，需移步设置-退款设置-设置好退款信息！才能生效！'),
						array('name'=>'status','title'=>'上架','type'=>'switch'),
						array('name'=>'no_onebuy','title'=>'不可单独购买？','type'=>'switch','help'=>'必须跟《可单独购买》的商品一起下单才行！'),
					)
				),
				array(
					'title'=>'快递配送',
					'show'=>array('type'=>0),
					'tovalue'=>'dispatch',
					'list'=>array(
						array('name'=>'fullnum','title'=>'单品满件包邮','type'=>'string','help'=>'不包邮请留空'),
						array('name'=>'fullmoney','title'=>'单品满额包邮','type'=>'string','help'=>'不包邮请留空'),
						array('name'=>'fullnoareas','title'=>'不参与单品包邮地区','type'=>'choose','action'=>'/shop.peisong/choose'),
						array('name'=>'type','title'=>'运费设置','type'=>'radio','options'=>'dispatchtype'),
						array('name'=>'template_id','title'=>'运费模版','type'=>'select','options'=>'dispatchid','show'=>array('type'=>0)),
						array('name'=>'weight','title'=>'商品重量','type'=>'string','help'=>'单位：千克','show'=>array('type'=>array(0,2))),
						array('name'=>'price','title'=>'统一运费','type'=>'string','show'=>array('type'=>1),'help'=>'统一运费后发往各地运费一致'),
					)
				),
				array(
					'title'=>'自提/核销',
					//'show'=>array('type'=>array(0,3)),
					'list'=>array(
						array('name'=>'isverify','title'=>'支持核销','type'=>'switch','show'=>array('type'=>array(0,1,2)),'help'=>'计次商品，默认开启核销'),
						array('name'=>'storeids','title'=>'选择线下门店','type'=>'choose_many','action'=>'jy_weishop_en/store.get_store/many/','choose_title'=>'选择门店','help'=>'门店信息--》设置门店，留空则所有门店都可以核销！开启核销或者设置-->商品详情设置-->开启门店显示，商品详情页才会显示门店，默认显示最近的一个！'),
						array('name'=>'verifytype','title'=>'核销方式','type'=>'radio','options'=>'verifytype','show'=>array('type'=>array(0,1,2)),'help'=>'按订单核销： 不管购买多少 一次核销完成按次核销： 一个消费码使用多次（购买的数量）按消费码核销： 多个消费码 一次核销一个'),
						array('name'=>'usetime','title'=>'自动使用期限','type'=>'string','show'=>array('type'=>array(0,1,2)),'help'=>'商品购买X天后自动使用，自动使用后无法退款，设置为0则没有限制'),
						array('name'=>'verifygoodsnum','title'=>'核销次数','type'=>'unitstring','unit'=>'次','show'=>array('type'=>array(3)),'help'=>'此商品可以核销次数,不填或填写0及以下为默认不限次数'),
						array('name'=>'verifygoodslimittype','title'=>'有效期类型','type'=>'radio','options'=>'verifygoodslimittype','show'=>array('type'=>array(3)),'help'=>'自购买之日起多少天内有效,不写默认365天'),
						array('name'=>'verifygoodsdays','title'=>'有效天数','type'=>'unitstring','unit'=>'天','show'=>array('type'=>array(3),'verifygoodslimittype'=>0),'help'=>'自购买之日起多少天内有效,不写默认365天'),
						array('name'=>'verifygoodslimitdate','title'=>'过期日期','type'=>'time','unit'=>'天','show'=>array('type'=>array(3),'verifygoodslimittype'=>1),'help'=>'无论何时购买此商品,到达指定时间后都将过期,无法核销.'),
					)
				),
				array(
					'title'=>'库存/规格/套餐',
					'list'=>array(
						array('name'=>'goodssn','title'=>'编码','type'=>'string','help'=>''),
						array('name'=>'productsn','title'=>'国家商品条码','type'=>'string','help'=>'这里是商品条码，例如：国家商品条码'),
						array('name'=>'isoffcode','title'=>'称码商品？','type'=>'switch'),
						array('name'=>'offcode','title'=>'商品称码','type'=>'string','help'=>'这里是：称码对接条码,如果已经设置了商品称码长度的话，不填的话系统会自动生成，位数由：设置-基础设置-称码对接-商品称码长度决定'),
						array('name'=>'offcodeunit','title'=>'选择秤码规则','type'=>'select','options'=>'offcodeunit','help'=>'如果为空，请移步：设置-基础设置-称码对接-秤码接入里面添加规则'),
						array('name'=>'total','title'=>'库存','type'=>'string','help'=>'<red>明明有库存，但是前端显示没库存?有可能前端指定了门店，该门店下该商品没有库存！</red>;</br><red>注意：两种情况库存不准</red>1、如果已经添加了多规格的，库存将自动计算规格库存的总和！2、你设置的卡密，但是卡密里面没有卡密数据了！'),
						array('name'=>'totalcnf','title'=>'减库存方式','type'=>'radio','options'=>'totalcnf'),
						array('name'=>'api_istaocan','title'=>'套餐商品？','type'=>'switch','isradio'=>'1'),
						array('type'=>'tip','show'=>array('api_istaocan'=>0),'title'=>'[<red>温馨提示</red>]：如果门店那边单独设置了该商品规格的价格，库存等；将以门店的为准！</br>【规格添加教程】：</br>1、点<red>添加规格</red>，再点<red>+添加规格项</red>；2、添加好之后再点《<red>刷新规格项目表</red>》；3、然后设置不同规格的价格，库存，图片等！'),
						array('name'=>'specs','title'=>'规格','type'=>'specs_new','show'=>array('api_istaocan'=>0)),
						array('type'=>'array','show'=>array('api_istaocan'=>1),'title'=>'个性套餐','name'=>'api_taocans','add_tip'=>'添加一组个性套餐',
							'list'=>array(
										array('type'=>'string','name'=>'title','title'=>'套餐名称'),
										array('type'=>'image','name'=>'thumb','title'=>'套餐图片'),	
										array('type'=>'string','name'=>'unit','title'=>'套餐单位'),
										array('type'=>'string','name'=>'goodsnum','title'=>'内含商品数量'),
										array('type'=>'unitstring','unit'=>'元','name'=>'price','title'=>'套餐定价'),	
										array('type'=>'unitstring','unit'=>'元','name'=>'productprice','title'=>'套餐原价'),
										array('type'=>'string','name'=>'stock','title'=>'库存'),
									),
									'details'=>array(
										array('type'=>'string','name'=>'title','title'=>'套餐名称'),
										array('type'=>'image','name'=>'thumb','title'=>'套餐图片'),	
										array('type'=>'string','name'=>'unit','title'=>'套餐单位'),
										array('type'=>'string','name'=>'goodsnum','title'=>'内含商品数量'),
										array('type'=>'unitstring','unit'=>'元','name'=>'price','title'=>'套餐定价'),
										array('type'=>'unitstring','unit'=>'元','name'=>'productprice','title'=>'套餐原价'),
										array('type'=>'unitstring','unit'=>'元','name'=>'costprice','title'=>'套餐成本价'),
										array('type'=>'string','name'=>'stock','title'=>'库存'),
									)
						),
					)
				),
				array(
					'title'=>'详情',
					'list'=>array(
						array('name'=>'salenum','title'=>'已出售数','type'=>'string'),
						array('name'=>'isshowsales','title'=>'不显示销量？','type'=>'switch','help'=>'如果总设置不显示，这里的设置将失效(设置--基础设置--其他设置)'),
						array('name'=>'isshowtotal','title'=>'是否显示库存','type'=>'switch','help'=>'如果总设置不显示，这里的设置将失效(设置--基础设置--其他设置)'),
						array('name'=>'pcd','title'=>'所在地','type'=>'pcd','help'=>'商品所在地，显示在商品详情页，如果不选择，则显示商城所在地'),
						array('type'=>'tip','title'=>'[<red>温馨提示</red>]：默认图片宽度是100%；图片之间不回车换行的话，追加在后面的话，图片之间就没有空白线！！'),
						array('name'=>'content','title'=>'详情','type'=>'richtextold','help'=>''),
						array('name'=>'buyshow','title'=>'购买后可见','type'=>'switch','help'=>'开启后购买过的商品才会显示下面内容！！'),
						array('name'=>'buycontent','title'=>'购买后显示内容','type'=>'richtext','help'=>''),
					)
				),
				array(
					'title'=>'参数',
					'list'=>array(
							array('type'=>'array','name'=>'param','add_tip'=>'添加一个参数',
										'list'=>array(
											array('type'=>'string','name'=>'title','title'=>'参数名称'),
											array('type'=>'string','name'=>'value','title'=>'参数值'),
										),
										'details'=>array(
											array('type'=>'radio','name'=>'type','title'=>'参数类型','options'=>'paramtype'),
											array('type'=>'string','name'=>'title','title'=>'参数名称','show'=>array('type'=>0)),
											array('type'=>'string','name'=>'value','title'=>'参数值','show'=>array('type'=>0)),		
											array('type'=>'select2_title','name'=>'title','title'=>'选择参数','show'=>array('type'=>1),'options'=>'params','name2'=>'value','title2'=>'参数值','options2'=>'content'),
										)
									),
					)
				),			
				array(
					'title'=>'定价/购买/权限',
					'list'=>array(
						array('name'=>'no_de_sales','title'=>'不参与的优惠活动','type'=>'checkbox','options'=>'de_sales'),
						array('name'=>'maxbuy','title'=>'单次最多购买','type'=>'string','help'=>''),
						array('name'=>'minbuynum','title'=>'单次最低购买','type'=>'string','help'=>''),
						array('name'=>'usermaxbuy','title'=>'最多购买','type'=>'string','help'=>''),
						array('name'=>'showlevels','title'=>'会员等级浏览权限','type'=>'checkbox','options'=>'levels','help'=>''),
						array('name'=>'buylevels','title'=>'会员等级购买权限','type'=>'checkbox','options'=>'levels','help'=>'商品分类，也可以指定权限'),
						array('name'=>'showgroups','title'=>'会员组浏览权限','type'=>'checkbox','options'=>'groups','help'=>''),
						array('name'=>'buygroups','title'=>'会员组购买权限','type'=>'checkbox','options'=>'groups','help'=>'商品分类，也可以指定权限'),
						array('name'=>'isdiyprice','title'=>'启用个性定价','type'=>'switch','help'=>'如果多商户组绑定了商城会员，商户下单优先按商户组绑定等级走；<red>个性定价</red>优选于会员折扣，如果所属会员设置了个性定价，会员折扣将失效。<red>带规格的商品，个性定价将无效</red>'),
						array('type'=>'array','title'=>'个性定价','name'=>'diyprice','add_tip'=>'添加一组个性定价',
							'list'=>array(
										array('type'=>'string','name'=>'price','title'=>'个性定价'),
										array('type'=>'string','name'=>'pricerate','title'=>'多规格定价%'),
										array('type'=>'select','name'=>'levelid','title'=>'所属会员等级','options'=>'levels2'),			
									),
									'details'=>array(
										array('type'=>'unitstring','unit'=>'元','name'=>'price','title'=>'个性定价','help'=>'必须是数字'),	
										array('type'=>'unitstring','unit'=>'%','name'=>'pricerate','title'=>'多规格定价%','help'=>'必须是数字，原规格的价格%'),
										array('type'=>'select','name'=>'levelid','title'=>'所属会员等级','options'=>'levels2','help'=>'无会员等级，请先移步会员-会员等级，添加！'),
									)
						),
					)
				),
				array(
					'title'=>'营销',
					'list'=>array(
						array('title'=>'更多营销设置，请移步-->活动营销,添加需要参与活动的商品！','type'=>'tip'),
						array('type'=>'title','title'=>'抵扣设置'),
						array('name'=>'isdiscount','title'=>'开启独立抵扣？','type'=>'switch','help'=>'默认按平台设置的抵扣！'),
						array('type'=>'switch','name'=>'deductset.deduct_credit1','title'=>'积分抵扣'),
						array('type'=>'unitstring','unit'=>'比1','name'=>'deductset.deduct_bili','title'=>'积分抵扣比例','help'=>'例如设置为10,即10积分抵1元,商品最多抵扣的数目需要在商品【营销设置】中单独设置'),
						array('type'=>'unitstring','unit'=>'%','name'=>'deductset.deduct_maxfeebili','title'=>'积分最大抵扣的额度比例','help'=>'必须是数字，默认50；积分最大抵扣的费用比例,例如50，表示最大可抵扣一半'),
						//array('type'=>'switch','name'=>'deductset.deduct_credit2','title'=>'余额抵扣','help'=>'余额属于等比例抵扣'),
						//array('type'=>'unitstring','unit'=>'元','name'=>'deductset.deduct_credit2max','title'=>'余额最大抵扣','help'=>'如果设置0留空，则支持全额抵扣'),
						array('type'=>'switch','name'=>'deductset.deduct_dispatch','title'=>'是否可以抵扣运费'),
						array('type'=>'title','title'=>'满返设置'),
						array('title'=>'积分/币赠送设置（需要移步：<red>营销-->购物送积分/购物送虚拟币--【启用】一下，【支付场景】：设置一下，【赠送时机】，设置一下</red>）','type'=>'tip'),
						array('type'=>'string','name'=>'fang_credit2','title'=>'余额返现','help'=>'会员购物返现, 如果不填写或填写0，则默认为不返现，如果带%则为按成交价格的比例计算返现</br> 如: 购买2件，设置10 元, 不管成交价格是多少， 则购买后获得20元返现</br>如: 购买2件，设置10%元, 成交价格2 * 100= 200， 则购买后获得 20 元返现（200*10%）'),
						array('type'=>'switch','title'=>'多币赠送？','name'=>'gcredit_sendtype','help'=>'开启后，可以设置多种赠送模式;'),
						array('type'=>'radio','title'=>'虚拟币类型','name'=>'gcredit_type','options'=>'xuni_types','show'=>array('gcredit_sendtype'=>0)),
						array('type'=>'string','name'=>'gcredit_credit','title'=>'赠送数量','help'=>'填写数字表示固定虚拟币；填写%，表示百分比计算虚拟币；','show'=>array('gcredit_sendtype'=>0)),
						array('type'=>'array','show'=>array('gcredit_sendtype'=>1),'name'=>'gcredit_credit_set','title'=>'赠送多币','add_tip'=>'添加一个赠送',
									'list'=>array(
										array('type'=>'radio','title'=>'虚拟币类型','name'=>'type','options'=>'xuni_types'),
										array('type'=>'string','name'=>'num','title'=>'赠送数量'),				
									),
									'details'=>array(
										array('type'=>'radio','title'=>'虚拟币类型','name'=>'type','options'=>'xuni_types'),
										array('type'=>'string','name'=>'num','title'=>'赠送数量'),	
									)
						),
						array('type'=>'title','title'=>'虚拟币设置'),
						array('title'=>'我的站点--支付参数--虚拟币设置（开启至少一个虚拟币，这里才会显示）','type'=>'tip'),
					)
				),
				array(
					'title'=>'分销设置',
					'list'=>array(
						array('title'=>'这里只显示基础分销的设置','type'=>'tip'),
						array('type'=>'title','title'=>'门店分佣设置'),
						array('type'=>'string','name'=>'commissions.store_sale','title'=>'门店绩效设置','help'=>'如果不填写或填写0，则默认为门店统一设置（门店--门店设置--门店绩效%），如果带%则为按成交价格的比例计算；如果是数字，表示是固定金额！'),
						array('type'=>'string','name'=>'commissions.store_order_rate','title'=>'门店分佣设置','help'=>'如果不填写或填写0，则默认为门店统一设置（门店--门店设置--门店分佣%），如果带%则为按成交价格的比例计算；如果是数字，表示是固定金额！'),
						array('type'=>'string','name'=>'commissions.store_workersale','title'=>'店员分佣设置','help'=>'如果不填写或填写0，则默认为门店统一设置（门店--门店设置--店员分佣%），如果带%则为按成交价格的比例计算；如果是数字，表示是固定金额！'),
						array('type'=>'radio','title'=>'分享奖励','name'=>'commissions.fen_feetype','options'=>'xuni_types','help'=>'只有分享给新用户才能获得奖励'),
						array('type'=>'unitstring','title'=>'分享奖励','unit'=>'个','name'=>'commissions.fen_feenum'),
					)
				),
				array(
					'title'=>'分享关注',
					'list'=>array(
						array('name'=>'needfollow','title'=>'购买强制关注','type'=>'radio','options'=>'needfollow','help'=>''),
						array('name'=>'followtip','title'=>'关注提示','type'=>'string','show'=>array('needfollow'=>'1'),'help'=>''),
						array('name'=>'followurl','title'=>'关注引导链接','type'=>'link','help'=>'购买商品关注，跳转的链接，如果为空默认为系统关注页'),
						array('name'=>'share_title','title'=>'分享标题','type'=>'string','help'=>''),
						array('name'=>'share_icon','title'=>'分享图标','type'=>'image','help'=>''),
						array('name'=>'share_desc','title'=>'分享描述','type'=>'text','help'=>'如果不填写，则使用商品副标题，如商品副标题为空则使用店铺名称'),
						array('name'=>'share_keywords','title'=>'页面关键词','type'=>'text','help'=>'如果不填写，则使用描述'),
					)
				),
				array(
					'title'=>'卖家通知',
					'list'=>array(
						array('name'=>'noticemid','title'=>'选择通知人','type'=>'choose_title','action'=>'core/member.get_member/','choose_title'=>'选择会员','help'=>'填系统会员ID'),
						array('name'=>'noticetype','title'=>'通知方式','type'=>'checkbox','options'=>'noticetype','help'=>''),
						
					)
				),
				array(
					'title'=>'自定义表单',
					'list'=>array(
								array('type'=>'tip','title'=>'[温馨提示]：优先显示商品自定义的表单，其次才显示统一表单：设置--自定义表单--商品订单自定义表单！'),
								array('name'=>'diyformtype','title'=>'自定义表单类型','type'=>'radio','options'=>'diyformtype','help'=>''),
								array('name'=>'diyformid','title'=>'选择表单模板','type'=>'select','options'=>'diyformtemp','show'=>array('diyformtype'=>2),'help'=>''),
								array('type'=>'array','show'=>array('diyformtype'=>1),'name'=>'diyfields','add_tip'=>'添加一个字段（温馨提示：已经有用户提交过数据的表单，不允许再编辑和添加新字段！）',
									'list'=>array(
										array('type'=>'string','name'=>'title','title'=>'字段名称'),	
										array('type'=>'radio','name'=>'type','title'=>'字段类型','options'=>'types'),	
									//	array('type'=>'string','name'=>'paixu','title'=>'排序'),	
										array('type'=>'string','name'=>'value','title'=>'选项信息'),	
									),
									'details'=>array(
										array('type'=>'string','name'=>'title','title'=>'字段名称'),	
										array('type'=>'select','name'=>'type','title'=>'字段类型','options'=>'filed_type','option_title'=>'type'),
									//	array('type'=>'string','name'=>'paixu','title'=>'排序','help'=>'从小到大顺序排序'),
										array('type'=>'string','name'=>'value','title'=>'选项信息','help'=>'单选和多选设置此条信息，选项之间以英文分号;隔开，例如:选项1;选项2;选项3'),
									)
								),	
					)
				),
				array(
					'title'=>'扩展属性',
					'list'=>array(
						array('name'=>'labelid','title'=>'选择标签组','type'=>'select','options'=>'labels','help'=>'选择标签组后，手机端商品详情会显示相应的标签！'),
						array('name'=>'iscashier','title'=>'支持收银台','type'=>'switch'),
						array('name'=>'cashpay','title'=>'货到付款','type'=>'switch'),
						array('name'=>'quality','title'=>'正品保证','type'=>'switch'),
						array('name'=>'invoice','title'=>'发票','type'=>'switch'),
						array('name'=>'repair','title'=>'保修','type'=>'switch'),
					)
				),
			)
		);
		$return['xuni_types']=credit_types();
		$return['de_sales']=$this->de_sales;
		//获取分类
		$groupspram=array('uniacid'=>$_SESSION['uniacid'],'mid'=>0,'parentid'=>0);
		$onepluginname=model('jy_weishop_en/goods')->is_onegoods($_SESSION['current_plugin'],$onepluginname);
		if($onepluginname){//开启独立商品
				$groupspram['onepluginname']=$onepluginname;
				$return['params']['onepluginname']=$onepluginname;
		}else{
				$groupspram['onepluginname']='';
		}
		$return['pcates']=pdo_getall('jy_weishop_goods_group',$groupspram,array('title','id'),'id');
		foreach($return['pcates'] as &$pv){
			$pv['ccates']=pdo_getall('jy_weishop_goods_group',array('uniacid'=>$_SESSION['uniacid'],'parentid'=>$pv['id']),array('title','id'),'id');
			foreach($pv['ccates'] as &$cv){
				$cv['scates']=pdo_getall('jy_weishop_goods_group',array('uniacid'=>$_SESSION['uniacid'],'parentid'=>$cv['id']),array('title','id'),'id');
			}
		}
		$xuni_types=$this->xuni_types;
		//$xuni_types[2]='余额';
		foreach($xuni_types as $k=>$xv){
			$htmls['edits'][7]['list'][]=array('type'=>'switch','name'=>'commissions.credit'.$k.'_diclose','title'=>$xv.'是否关闭抵扣');
			$htmls['edits'][7]['list'][]=array('type'=>'unitstring','unit'=>'%','title'=>$xv.'最大抵现比例','name'=>'commissions.credit'.$k.'_dirate','help'=>'默认100%抵扣，如果填写50，表示最大抵扣订单额度的50%');
			if($k>2){
				$htmls['edits'][7]['list'][]=array('type'=>'unitstring','unit'=>'个','title'=>'返'.$xv,'name'=>'commissions.credit'.$k.'_fan','help'=>'默认不返，填写具体数字后，返多少'.$xv);
			}
		}
		if($this->plugin_exists('jy_supplier') && $return['item']['supplier_id']){
			$return['item']['supplier_title']=pdo_getcolumn('jy_supplier_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$return['item']['supplier_id']),'merchname');
			$htmls['edits'][0]['list'][]=array('name'=>'supplier_title','title'=>'所属供货商','type'=>'copy','help'=>'由供货商发布的商品！');
		}
		if($this->plugin_exists('jy_commission')){
			$jy_commission=model('jy_commission/model')->getgoodshtml($return['item']['id']);
			if($jy_commission && $jy_commission['item']){
				$return['jy_commissionlevels']=$jy_commission['levels'];
				$return['item']=array_merge($return['item'],$jy_commission['item']);
				foreach($jy_commission['htmls'] as $jv){
					$htmls['edits'][8]['list'][]=$jv;
				}
			}
		}
		$dispatchtype=array('0'=>'运费模板','1'=>'统一运费','2'=>'默认模板');
		$totalcnf=array('0'=>'拍下减库存','1'=>'付款减库存','2'=>'永不减库存');
		$needfollow=array('0'=>'否','1'=>'是');
		$noticetype=array('1'=>'付款通知','2'=>'买家收货通知');
		$verifytype=array('0'=>'按订单核销','1'=>'按次核销','2'=>'按消费码核销');
		$return['verifygoodslimittype']=array('0'=>'购买后有效','1'=>'指定过期日期');
		$diyformtype=array('0'=>'关闭','1'=>'自定义','2'=>'使用模板');
		$presellsendtimetype=array('0'=>'固定时间','1'=>'购买时间');
		$return['diyformtemp']=pdo_getall('jy_weishop_diyform_temp',array('uniacid'=>$_SESSION['uniacid']));
		$return['storeids']=pdo_getall('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
		$return['labels']=pdo_getall('jy_weishop_goods_label',array('uniacid'=>$_SESSION['uniacid'],'status'=>1),array('id','title'),'id');
		$levels=pdo_getall('jy_weishop_member_level',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
		$return['levels2']=$levels;
		$return['levels']=array();
		$return['levels'][0]='默认会员';
		foreach($levels as $lv){
			$return['levels'][$lv['id']]=$lv['title'];
		}
		$groups=pdo_getall('jy_weishop_member_group',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
		$return['groups']=array();
		foreach($groups as $lv){
			$return['groups'][$lv['id']]=$lv['title'];
		}
		$return['params']=pdo_getall('jy_weishop_goods_param',array('uniacid'=>$_SESSION['uniacid'],'status'=>1),'','title');
		foreach($return['params'] as &$pv){
			$pv['content']=json_decode($pv['content'],true);
		}
		$return['dispatchid']=pdo_getall('jy_weishop_dispatch',array('uniacid'=>$_SESSION['uniacid'],'status'=>1),array('id','title'),'id');
		$return['type']=$this->goods_types;
		$return['saletype']=$this->saletypes;
		$return['dispatchtype']=$dispatchtype;
		$return['totalcnf']=$totalcnf;
		$return['status']=$status;
		$return['needfollow']=$needfollow;
		$return['noticetype']=$noticetype;
		$return['verifytype']=$verifytype;
		$return['diyformtype']=$diyformtype;
		$return['htmls']=$htmls;
		$return['virtual_templates']=pdo_getall('jy_weishop_virtual_temp',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
		$return['filed_type']=array(array('id'=>1,'type'=>'字符串'),array('id'=>2,'type'=>'数字'),array('id'=>3,'type'=>'图片'),array('id'=>4,'type'=>'单选'),array('id'=>5,'type'=>'多选'),array('id'=>6,'type'=>'文本'),array('id'=>7,'type'=>'地址'));
		$return['types']=array('1'=>'字符串','2'=>'数字','3'=>'图片','4'=>'单选框','5'=>'多选框','6'=>'文本','7'=>'地址');
		$return['paramtype']=array('自定义参数','选择公共参数');
		return $return;
	}
	/*
		商品数据
	*/
	public function postdata($postdata){
		if($postdata['isbuyxiu']){
			$install = check_permission('jy_vote');
			if(empty($install)){
				exi('没有安装《场景投票》应用，不能开启‘买家秀’！','error');
			}
		}
		if(!$postdata['title']){
			exi('必须设置商品名称','error');
		}
		if(!$postdata['image']){
			exi('必须设置商品图片','error');
		}
		if($postdata['price'] <0){
			exi('商品价格不能小于0！','error');
		}
		if(!$postdata['content']){
			//exi('必须设置商品详情','error');
		}
		$shopset=$this->plugin_setting('shopset');
		if(!$shopset['goodscodenum'] && $postdata['offcode']){
			exi('还未设置称码长度，不能设置商品称码','error');
		}
		if($shopset['goodscodenum']!=mb_strlen($postdata['offcode'])){
			exi('商品称码必须设置'.$shopset['goodscodenum'].'位数','error');
		}
		//计算卡密
		if($postdata['type']==2){
			$count=pdo_count('jy_weishop_virtual_data',array('uniacid'=>$_SESSION['uniacid'],'tempid'=>intval($postdata['virtual_template_id']),'mid'=>0),'id');
			if($count<intval($postdata['total'])){
				exi('你设置的库存不能大于：选择的卡密的库存数据！','error');
			}
		}
		//定价策略
		$setprice=$this->plugin_setting('setprice');
		if($postdata['costprice']>0 && $setprice && $setprice['set']){
			foreach($setprice['set'] as $sv){
				if(!$sv['pricerate'] || !$sv['levelid']){
					continue;
				}
				$isset=false;
				$pirce=$postdata['costprice']+$postdata['costprice']*$sv['pricerate']/100;
				if($setprice['isint']){
					$pirce=round($pirce);
				}
				foreach($postdata['diyprice'] as &$dpv){
					if($sv['levelid'] && $sv['levelid']==$dpv['levelid']){
						$isset=true;
						if(!$dpv['price'] && $postdata['costprice']>=$sv['minprice'] && $postdata['costprice']<=$sv['maxprice']){
							$dpv['price']=$pirce;
							break;
						}
					}
				}
				if(!$isset){
					if($postdata['costprice']>=$sv['minprice'] && $postdata['costprice']<=$sv['maxprice']){
						$postdata['diyprice'][]=array(
							'price'=>$pirce,
							'levelid'=>$sv['levelid'],
						);
						$isupprice=true;
					}
				}
			}
		}
		if($isupprice){
			$postdata['isdiyprice']=1;
		}
		$postdata['deductset']['deduct_bili']=intval($postdata['deductset']['deduct_bili']);
		$postdata['deductset']['deduct_maxfeebili']=$postdata['deductset']['deduct_maxfeebili'];
		$postdata['api_data']['no_oldprice']=intval($postdata['no_oldprice']);
		$postdata['api_data']['no_oldpriceline']=intval($postdata['no_oldpriceline']);
		$postdata['api_data']['oldpricetitle']=$postdata['oldpricetitle'];
		$postdata['api_data']['istaocan']=intval($postdata['api_istaocan']);
		$data=array(
			'title'=>trim($postdata['title']),
			'image'=>trim($postdata['image']),
			'video'=>trim($postdata['video']),
			'subtitle'=>trim($postdata['subtitle']),
			'shorttitle'=>trim($postdata['shorttitle']),
			'keywords'=>trim($postdata['keywords']),
			'saletype'=>trim($postdata['saletype']),
			'type'=>intval($postdata['type']),
			'paixu'=>intval($postdata['paixu']),
			'price'=>floatval($postdata['price']),
			'originalprice'=>floatval($postdata['originalprice']),
			'marketprice'=>floatval($postdata['marketprice']),
			'costprice'=>floatval($postdata['costprice']),
			'images'=>ijson_encode($postdata['images']),
			'quality'=>intval($postdata['quality']),
			'salenum'=>intval($postdata['salenum']),
			'unit'=>$postdata['unit']?trim($postdata['unit']):'件',
			'isshowsales'=>intval($postdata['isshowsales']),
			'status'=>intval($postdata['status']),
			'pcd'=>ijson_encode($postdata['pcd']),
			'iscashier'=>intval($postdata['iscashier']),
			'invoice'=>intval($postdata['invoice']),
			'cashpay'=>intval($postdata['cashpay']),
			'repair'=>intval($postdata['repair']),
			'seven'=>intval($postdata['seven']),
			'virtualsendcont'=>trim($postdata['virtualsendcont']),
			'virtual_template_id'=>intval($postdata['virtual_template_id']),
			
			'virtualsend'=>intval($postdata['virtualsend']),
			//库存
			'goodssn'=>trim($postdata['goodssn']),
			'productsn'=>trim($postdata['productsn']),
			
			'isshowtotal'=>intval($postdata['isshowtotal']),
			'total'=>intval($postdata['total']),
			'totalcnf'=>intval($postdata['totalcnf']),
			
			//参数
			'param'=>ijson_encode($postdata['param']),
			//详情
			'content'=>trim($postdata['content']),
			'buyshow'=>intval($postdata['buyshow']),
			'buycontent'=>trim($postdata['buycontent']),
			//购买权限
			'no_de_sales'=>trim($postdata['no_de_sales']),
			'maxbuy'=>intval($postdata['maxbuy']),
			'minbuynum'=>intval($postdata['minbuynum']),
			'usermaxbuy'=>intval($postdata['usermaxbuy']),
			'showlevels'=>trim($postdata['showlevels']),
			'buylevels'=>trim($postdata['buylevels']),
			'showgroups'=>trim($postdata['showgroups']),
			'buygroups'=>trim($postdata['buygroups']),
			//DIY价格
			'isdiyprice'=>intval($postdata['isdiyprice']),
			'diyprice'=>ijson_encode($postdata['diyprice']),
			//分享关注
			'needfollow'=>intval($postdata['needfollow']),
			'followtip'=>trim($postdata['followtip']),
			'followurl'=>trim($postdata['followurl']),
			'share_title'=>trim($postdata['share_title']),
			'share_icon'=>trim($postdata['share_icon']),
			'share_desc'=>trim($postdata['share_desc']),
			'share_keywords'=>trim($postdata['share_keywords']),
			//卖家通知
			'noticemid'=>intval($postdata['noticemid']),
			'noticetype'=>trim($postdata['noticetype']),
			
			//核销
			'isverify'=>intval($postdata['isverify']),
			'verifytype'=>intval($postdata['verifytype']),
			'usetime'=>intval($postdata['usetime']),
			'verifygoodsnum'=>intval($postdata['verifygoodsnum']),
			'verifygoodsdays'=>intval($postdata['verifygoodsdays']),
			'verifygoodslimittype'=>intval($postdata['verifygoodslimittype']),
			'verifygoodslimitdate'=>intval(strtotime($postdata['verifygoodslimitdate'])),
			//店铺信息
			'storeids'=>ijson_encode($postdata['storeids']),
			//营销设置
			'isdiscount'=>intval($postdata['isdiscount']),
			'deductset'=>ijson_encode($postdata['deductset']),
			'fang_credit2'=>trim($postdata['fang_credit2']),
			//分销设置
			'commissions'=>ijson_encode($postdata['commissions']),
			//自定义表单
			'diyfields'=>$postdata['diyfields']?ijson_encode($postdata['diyfields']):'',
			'diyformid'=>intval($postdata['diyformid']),
			'diyformtype'=>intval($postdata['diyformtype']),
			//扩展属性
			'labelid'=>intval($postdata['labelid']),
			'isoffcode'=>intval($postdata['isoffcode']),
			'offcode'=>trim($postdata['offcode']),
			'offcodeunit'=>trim($postdata['offcodeunit']),		
			'groupprice'=>trim($postdata['groupprice']),
			'groupnum'=>trim($postdata['groupnum']),
			'grouptime'=>trim($postdata['grouptime']),
			'no_onebuy'=>intval($postdata['no_onebuy']),
			'pcate'=>intval($postdata['pcate']),
			'ccate'=>intval($postdata['ccate']),
			'scate'=>intval($postdata['scate']),
			'api_data'=>ijson_encode($postdata['api_data']),
		);
		if(!$postdata['pluginname'] && $postdata['onepluginname']){
			$data['pluginname']=$postdata['onepluginname'];
		}
		//如果商品类型为计时/计次商品，默认开启核销
		if($data['type']=='3'){
			$data['isverify']=1;
		}
		//供货商
		if($postdata['supplier_id']){
			$data['api_id']=$postdata['supplier_id'];
			$data['api_pluginname']='jy_supplier';
		}
		return $data;
	}
	public function postup($postdata,$goodsid){
		//实体商品快递配送相关字段入库
		if($postdata['type']==0){
			$dispatch=array(
				'fullnum'=>intval($postdata['dispatch']['fullnum']),
				'fullmoney'=>intval($postdata['dispatch']['fullmoney']),
				'fullnoareas'=>trim($postdata['dispatch']['fullnoareas']),
				'type'=>intval($postdata['dispatch']['type']),
				'template_id'=>intval($postdata['dispatch']['template_id']),
				'weight'=>round($postdata['dispatch']['weight'],2),
				'price'=>round($postdata['dispatch']['price'],2),
			);
			$check=pdo_getcolumn('jy_weishop_goods_dispatch',array('goodsid'=>$goodsid),'goodsid');
			if($check){
				pdo_update('jy_weishop_goods_dispatch',$dispatch,array('goodsid'=>$goodsid));
			}else{
				$dispatch['goodsid']=$goodsid;
				$dispatch['uniacid']=$_SESSION['uniacid'];
				pdo_insert('jy_weishop_goods_dispatch',$dispatch);
			}
		}
		//整理商品规格数据
		if($postdata['specs']){
			$spec_ids=array();//接收当前生效的规格ID
			$spec_option_ids=array();//接收当前生效的规格项ID
			$spec_goods_ids=array();//接收当前生效的规格商品ID
			//第一步，整理规格和规格项
			foreach($postdata['specs']['specs'] as $spec_key=>&$spec){
				if(!intval($spec['id'])){				
					//数据库里面没有该规格
					$new_spec=array(
						'uniacid'=>$_SESSION['uniacid'],
						'goodsid'=>$goodsid,
						'paixu'=>$spec_key,
						'title'=>$spec['title'],
					);
					pdo_insert('jy_weishop_goods_spec',$new_spec);
					$spec['oldid']=$spec['id'];
					$spec['id']=pdo_insertid();
				}else{
					pdo_update('jy_weishop_goods_spec',array('title'=>$spec['title']),array('id'=>$spec['id']));
				}
				$spec_ids[]=$spec['id'];
				foreach($spec['options'] as $option_key=>&$option){
					if(!intval($option['id'])){
						$new_spec_option=array(
							'uniacid'=>$_SESSION['uniacid'],
							'goodsid'=>$goodsid,
							'specid'=>$spec['id'],
							'title'=>$option['title'],
							'paixu'=>$option_key,
						);
						pdo_insert('jy_weishop_goods_spec_item',$new_spec_option);
						$option['oldid']=$option['id'];
						$option['id']=pdo_insertid();
					}else{
						pdo_update('jy_weishop_goods_spec_item',array('title'=>$option['title']),array('id'=>$option['id']));
					}
					$spec_option_ids[]=$option['id'];
				}
			}
			//第二步，整理规格商品数据
			foreach($postdata['specs']['tds'] as $key=>$spec_goods){	
				$data=array(
					'paixu'=>$key,
					'thumb'=>trim($spec_goods['image']),
					'stock'=>intval($spec_goods['num']),
					'price'=>$spec_goods['price'],
					'productprice'=>$spec_goods['old_price'],
					'costprice'=>$spec_goods['cost_price'],
					'goodssn'=>trim($spec_goods['bm']),
					'productsn'=>trim($spec_goods['tm']),
					'weight'=>round($spec_goods['weight'],2),
				);
				if($spec_goods['id']){
					pdo_update('jy_weishop_goods_option',$data,array('id'=>intval($spec_goods['id']),'uniacid'=>$_SESSION['uniacid']));
				}else{
					//新的规格商品，根据规格值找到相应规格ID
					$data['specs']=array();
					foreach($postdata['specs']['specs'] as $sp){
						$sp_id=$sp['oldid']?:$sp['id'];
						foreach($sp['options'] as $op){
							$op_id=$op['oldid']?:$op['id'];
							if($spec_goods[$sp_id] && $spec_goods[$sp_id]['id']==$op_id){
								$data['specs'][]=$op['id'];
								break;
							}
						}
					}
					$data['specs']=implode('_',$data['specs']);
					$data['uniacid']=$_SESSION['uniacid'];
					$data['goodsid']=$goodsid;
					pdo_insert('jy_weishop_goods_option',$data);
					$spec_goods['id']=pdo_insertid();
				}
				$spec_goods_ids[]=$spec_goods['id'];
			}
			//清理数据库中弃用的规格、规格项、规格商品
			if(!empty($spec_ids)){
				pdo_delete('jy_weishop_goods_spec',array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$goodsid,'id !='=>$spec_ids));
			}else{
				pdo_delete('jy_weishop_goods_spec',array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$goodsid));
			}
			if(!empty($spec_option_ids)){
				pdo_delete('jy_weishop_goods_spec_item',array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$goodsid,'id !='=>$spec_option_ids));
			}else{
				pdo_delete('jy_weishop_goods_spec_item',array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$goodsid));
			}
			if(!empty($spec_goods_ids)){
				pdo_delete('jy_weishop_goods_option',array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$goodsid,'id !='=>$spec_goods_ids));
			}else{
				pdo_delete('jy_weishop_goods_option',array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$goodsid));
			}
		}
		//整理商品套餐
		if($postdata['api_taocans']){
			foreach($postdata['api_taocans'] as $pv){
				$data=array(
					'title'=>trim($pv['title']),
					'thumb'=>trim($pv['thumb']),
					'unit'=>trim($pv['unit']),
					'goodsnum'=>intval($pv['goodsnum']),
					'stock'=>intval($pv['stock']),
					'price'=>$pv['price'],
					'productprice'=>$pv['productprice'],
					'costprice'=>$pv['costprice'],
					'goodssn'=>trim($pv['goodssn']),
					'productsn'=>trim($pv['productsn']),
				);
				if($pv['id']){
					pdo_update('jy_weishop_goods_option',$data,array('id'=>intval($pv['id']),'uniacid'=>$_SESSION['uniacid']));
				}else{
					$data['uniacid']=$_SESSION['uniacid'];
					$data['goodsid']=$goodsid;
					pdo_insert('jy_weishop_goods_option',$data);
				}
			}
		}
		if($postdata['api_taocans'] || $postdata['specs']){
			$options = pdo_getall('jy_weishop_goods_option',array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$goodsid),'price','','price asc');
			$options2 = pdo_getall('jy_weishop_goods_option',array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$goodsid),'price','','price desc');
			if($options){
				$upgoods =array();
				$upgoods['minprice'] = $options[0]['price'];
				$upgoods['maxprice'] = $options2[0]['price'];
				$upgoods['total'] = pdo_getsum('jy_weishop_goods_option',array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$goodsid),'stock');
				pdo_update('jy_weishop_goods',$upgoods,array('id'=>$goodsid,'uniacid'=>$_SESSION['uniacid']));
			}
		}
		if($this->plugin_exists('jy_commission')){
			$post=array(
				'id'=>intval($postdata['jy_commission_id']),
				'goods_id'=>$goodsid,
				'ignore'=>intval($postdata['jy_commission_ignore']),
				'commissions'=>$postdata['jy_commission'],
			);
			model('jy_commission/model')->upgoods($post);
		}
		//虚拟币赠送
		$data=array(
			'type'=>intval($postdata['gcredit_type']),
			'is_jieti'=>intval($postdata['is_jieti']),
			'credit'=>$postdata['gcredit_credit'],
			'sendtype'=>intval($postdata['gcredit_sendtype']),
			'credit_set'=>ijson_encode($postdata['gcredit_credit_set']),
		);
		$gcredit_id=intval($postdata['gcredit_id']);
		if($gcredit_id){
			pdo_update('jy_weishop_goods_credit',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$gcredit_id));
		}else{
			$insert=array(
				'goods_id'=>$goodsid,
				'uniacid'=>$_SESSION['uniacid'],
				'createtime'=>TIMESTAMP,
			);
			$insert=array_merge($insert,$data);
			pdo_insert('jy_weishop_goods_credit',$insert);
		}
		return false;
	}
}